<?php
namespace app\website\controller;
use app\ApiRest;
use app\diy\model\DiyModel;
use app\payclass\model\Banner;
use app\shop\model\IndexCoupon;
use app\shop\model\IndexCouponRecord;
use app\website\model\CardauthConfig;
use app\card\model\CardExtension;
use app\card\model\CardUserLabel;
use app\Common\model\LongbingTabbar;
use app\website\model\CardGoods;
use app\base\model\CardTabBar;
use app\website\model\CardCompany;
use app\website\model\CardForm;
use app\website\model\CardModular;
use app\website\model\CardTimeline;
use app\website\model\CardTimelineComment;
use app\website\model\CardTimelineThumbs;
use app\website\model\CardUser;
use app\website\model\CardVideoCategory;
use app\website\model\PayQrConfig;
use app\website\model\PayQrRecord;
use app\website\model\StarBanner;
use app\website\model\StarCate;
use app\website\model\StarChoose;
use app\website\model\StarList;
use app\website\model\UserInfo;
use app\website\model\UserPhone;
use app\website\model\PayqrCarousel;
use app\website\model\UserSend;
use app\shop\controller\IndexWxPay;
use app\shop\model\IndexShopCollage;
use app\shop\model\IndexUserInfo;
use app\website\validate\ModularMsg;
use think\App;
use app\website\validate\CardTimelineCommnets;
use think\facade\Cache;
use think\facade\Db;

class Index extends ApiRest
{
    protected $CardModular;
    protected $page;
    protected $list_rows;
    // 继承 验证用户登陆
    public function __construct ( App $app )
    {
        parent::__construct( $app );
        $this->CardModular = new CardModular();

        $this->CardModular->releaseTimeArticle();

        $this->page = isset( $this->_param[ 'page' ] ) ? $this->_param[ 'page' ] : 1;
        $this->list_rows = isset( $this->_param[ 'list_rows' ] ) ? $this->_param[ 'list_rows' ] : 10;
    }
    public function index()
    {
        $verify = [ 'staff_id' => 'required' ];
        $params = lbGetParamVerify( $this->_param, $verify );
        $carousel = new CardCompany();
        $userinfo = new IndexUserInfo();
        $wherefan=[
          'fans_id' => $params['staff_id']
        ];
        $list = getCache('modular_index');
        //if(!$list){
            $companyid = $userinfo->getCompanyId($wherefan);
            if($this->page ==1){
                $wherecarousel = [
                    'id'=>$companyid
                ];
                $list['carousel'] = $carousel->getImg($wherecarousel);
                $wheres = [
                    'uniacid'=>$this->_uniacid,
                    'status'=>1,
                    'show_top'=>1,
                ];
                $list['model'] = $this->CardModular->list_nopage($wheres);
            }
            $where = [
                'uniacid'=>$this->_uniacid,
                'status'=>1,
                'show'=>1,
            ];


            $list['modular'] = $this->CardModular->listGroupV2($this->page,$this->list_rows,$where);
            //setCache('modular_index',$list);
        //}
        return $this->success($list);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-06-12 11:47
     * @功能说明:官网首页diy版
     */
    public function websiteList(){

        //获取diy的数据
        $diy_data = DiyModel::where([['status', '=', 1],['uniacid', '=', $this->_uniacid]])->find();
        //获取商城的
        $page_data= json_decode($diy_data['page'], true)[4] ?? [];
        //判断有没有diy过
        if(empty($page_data)|| (array_key_exists('list',$page_data) && empty($page_data['list']))){

//            $page_data = longbing_default_Page(4);

            return $this->success([]);

        }

        $verify   = [ 'staff_id' => 'required' ];

        $params   = lbGetParamVerify( $this->_param, $verify );

        $carousel = new CardCompany();

        $userinfo = new IndexUserInfo();


        foreach ($page_data['list'] as &$value){

            //轮播图
            if($value['type']=='banner'&&empty($value['data']['bannerList'])) {

                $wherefan = [

                    'fans_id' => $params['staff_id']
                ];

                $companyid = $userinfo->getCompanyId($wherefan);

                $wherecarousel = [

                    'id'=>$companyid
                ];

                $value['data']['bannerList'] = $carousel->bannerList($wherecarousel);

            }
            //导航栏
            if($value['type']=='column'&&empty($value['data']['columnList'])) {

                $wheres = [

                    'uniacid' => $this->_uniacid,

                    'status'  => 1,

                    'show_top'=> 1,
                ];

                $value['data']['columnList'] = $this->CardModular->listNopageDiy($wheres,'name as title,type,cover as img');
            }

            $type_arr = ['articleList','starList', 'imageText', 'recruitInfo','contactUs','staffList','videoModule','formModule'];
            //列表
            if(in_array($value['type'],$type_arr)&&empty($value['data']['dataList'])&&!empty($value['data']['modular'])) {


                $where = [
                    'uniacid'=> $this->_uniacid,

                    'status' => 1,

                    'show'   => 1,

                    'id'     => $value['data']['modular']
                ];

                $page_limit = !empty($value['data']['row']['number'])?$value['data']['row']['number']:0;

                $data_page = $this->CardModular->listGroupV2Diy($page_limit,$where);

                $value['data']['dataList'] = $data_page;
            }



            //优惠券
            if($value['type']=='couponList'&&empty($value['data']['dataList'])) {

                $coupon_model = new IndexCoupon();

                $coupon_record= new IndexCouponRecord();

                $coupon_dis = ['status'=>1,'uniacid'=>$this->_uniacid];

                $dataList   = $coupon_model->couponListSelect($coupon_dis,$this->getUserId(),$params['staff_id']);

                if(!empty($dataList)){
                    //列表样式
                    if($value['data']['type']==2){

                        $value['data']['dataList'] = $dataList;

                    }else{
                        //弹窗样式
                        $value['data']['dataList']['coupon'] = $dataList[0];
                        //领取记录
                        $r_dis = [
                            //优惠券id
                            'coupon_id' => $dataList[0]['id'],
                            //员工
                            'staff_id'  => $params['staff_id'],
                            //uniacid
                            'uniacid'   => $this->_uniacid
                        ];

                        $value['data']['dataList']['coupon_last_record'] = $coupon_record->where($r_dis)->limit(3)->order('id desc')->select()->toArray();

                        if ( !empty(  $value['data']['dataList']['coupon_last_record'] ) )
                        {

                            foreach (  $value['data']['dataList']['coupon_last_record'] as $index => $item )
                            {
//
                                $user = longbingGetUser($item[ 'user_id' ] ,$this->_uniacid);
                                if ( mb_strlen( $user[ 'nickName' ], 'utf8' ) > 4 )
                                {
                                    $user[ 'nickName' ] = mb_substr( $user[ 'nickName' ], 0, 4, "UTF-8" );
                                }

                                $value['data']['dataList']['coupon_last_record'][ $index ][ 'user_info' ] = $user;
                            }

                        }
                    }
                }
            }
        }
        return $this->success($page_data);
    }


    public function info(){
        $verify = [ 'id' => 'required'];
        $params = lbGetParamVerify( $this->_param, $verify );
        $where = [
            'status'=>1,
            'uniacid'=>$this->_uniacid,
        ];
        $list = $this->CardModular->listinfo($params[ 'id' ],$this->page,$this->list_rows,$where,$type=0,$keyword='',$this->_param);
        return $this->success($list);
    }
    public function info_details(){
        $verify = [ 'id' => 'required','modular_id'=>'required','staff_id'=>'required'];
        $params = lbGetParamVerify( $this->_param, $verify );
        $list['list'] = $this->CardModular->infoDetail($params);
        $card_company = new CardCompany();
        $userinfo = new IndexUserInfo();
        $company_id  = $userinfo->getCompanyId(['fans_id'=>$params['staff_id']]);
        //找到公司最上级
        $company_id = $card_company->getUserTopCompanyId($company_id);
        $company = $card_company->getinfo(['uniacid'=>$this->_uniacid,'id'=>$company_id]);
        $list['staff'] = $company;
        return $this->success($list);
    }
    public function message(){
        $data = $this->_input;
        $validate = new ModularMsg();
        $result = $validate->check($data);
        if(!$result){
            return $this->error($validate->getError());
        }
        $from = new CardForm();
        $data['bac1'] = $this->getUserId();
        $data['uniacid'] = $this->_uniacid;

        $data['imgs'] = !empty($data['imgs'])?implode(',',$data['imgs']):'';

        unset($data['staff_id']);

        $res = $from->createRow($data);

        if ($res === false)
        {
            return $this->error('operation failed');
        }
        return $this->success( [] );
    }
    public function create_timeline(){
        $verify = [ 'content' => 'required','cover' => 'required'];
        $params = lbGetParamVerify( $this->_input, $verify );
        if(!empty($params['cover'])&&is_array($params['cover'])){
            $params['cover'] = implode(',',$params['cover']);
        }
        $user = new UserInfo();
        $user_id = $this->getUserId();
        $user_info = $user->cardList(['fans_id'=>$user_id,'is_staff'=>1]);
        if(!$user_info){
            return $this->error('用户还不是员工');
        }
        $params['uniacid'] = $this->_uniacid;
        $params['user_id'] = $user_id;
        if(mb_strlen($params['content'])>10){
            $params['title'] = mb_substr($params['content'], 0,10);
        }else{
            $params['title'] = $params['content'];
        }
        $timeline = new CardTimeline();
        $res = $timeline->createRow($params);
        if ($res === false)
        {
            return $this->error('operation failed');
        }
        return $this->success( [] );
    }
    //动态
    public function timeline(){
        $staff_id = $this->_param['staff_id'];
        $line = new CardTimeline();
        $userId   = $this->getUserId();
        if($staff_id){
            $userinfo = new IndexUserInfo();
            $company_id  = $userinfo->getCompanyId(['fans_id'=>$staff_id]);
            $where['a.user_id'] = ['in',"$staff_id,$company_id"];
        }else{
            $where['a.user_id'] = $userId;
        }
        $where['a.uniacid'] = $this->_uniacid;
        $where['a.status'] = 1;
        $list = $line->dtlist($this->page,$this->list_rows,$where,$staff_id,$userId);
        $list[ 'data' ] = formatDefaultImage( $list[ 'data' ], 'avatarUrl', 'avatar', $this->defaultImage );
        return $this->success($list);
    }
    public function timeline_details(){
        $verify = [ 'id' => 'required','staff_id' => 'required'];
        $params = lbGetParamVerify( $this->_param, $verify );
        $line = new CardTimeline();
        $where['a.id'] = $params['id'];
        $params['user_id'] = $this->getUserId();
        $info = $line->get_info($where,$params,$this->page,$this->list_rows);
        if(!$info['avatarUrl']){
            $info = formatDefaultImage( $info, 'avatarUrl', 'avatar', $this->defaultImage );
        }
        return $this->success($info);
    }
    //动态删除
    public function timeline_del(){
        $verify = [ 'id' => 'required'];
        $params = lbGetParamVerify( $this->_input, $verify );
         $timeline = new CardTimeline();
        $user = $this->getUserId();
        $user_id = $timeline->getUserid($params['id']);
        if($user !== $user_id){
            return $this->error('不能删除它人的动态');
        }
        $timeline->upsave(['id'=>$params['id']],['status'=>-1]);
        return $this->success([]);
    }
    public function timeline_qr(){
        $data=$this->_input;
        $verify = [ 'id' => 'required','staff_id' => 'required'];
        $params = lbGetParamVerify( $data, $verify );
        $timeline = new CardTimeline();
        $line_id = $timeline->getID($params['id']);
        if(!$line_id){
            return $this->error('动态不存在');
        }
        $params['pid'] = $this->getUserId();
        $params['type'] = 3;
        $rest      = longbingCreateWxCode($this->_uniacid,$params,'pages/info/detail');
        if(isset($rest['qr_path'])) $rest = transImagesOne($rest ,['qr_path'] ,$this->_uniacid);
        $coupon_qr = $rest['qr_path'];
        return $this->success($coupon_qr);
    }
    //点赞
    public function fabulous(){
        $data = $this->_input;
        $validate = new \app\validate\CardTimelineThumbs;
        $result = $validate->check($data);
        if(!$result){
            return $this->error($validate->getError());
        }
        $userId   = $this->getUserId();
        $thumds = new CardTimelineThumbs();
        $timeline = new CardTimeline();
        $line_user_id = $timeline->getUserid($data['timeline_id']);
        if($line_user_id == $userId){
            return $this->error('不能给自己点赞');
        }
        $id  = $thumds->is_fabulous($userId,$data['timeline_id'],$this->_uniacid);
        // 启动事务
        Db::startTrans();
        try {
            if(!$id){
                $data = [
                    'user_id'=>$userId,
                    'timeline_id'=>$data['timeline_id'],
                    'status'=>1,
                    'uniacid'=>$this->_uniacid,
                ];
                 $thumds->createTimelineThumb($data);
                $timeline->where('id',$data['timeline_id'])->inc('thumb')->update();
            }else{
                $thumds->delTimelineThumb($id);
                $timeline->where('id',$data['timeline_id'])->dec('thumb')->update();
            }
            // 提交事务
            Db::commit();
            return $this->success( [] );
        } catch (\Exception $e) {
            // 回滚事务
            //print_r($e->getMessage());exit;
            return $this->error( '数据错误');
        }
    }
    public function comments(){
        $data = $this->_input;
        $validate = new  CardTimelineCommnets();
        $result = $validate->check($data);
        if(!$result){
            return $this->error($validate->getError());
        }
        $comment = new CardTimelineComment();
        $access_token = getAccessToken($this->_uniacid);
        $rest = $comment->wxContentRlue($data['content'],$access_token);
        if($rest['errcode'] != 0){
            return $this->error('内容含有违法违规内容');
        }
        $timeline = new CardTimeline();
        $line_user_id = $timeline->getUserid($data['timeline_id']);
        $userId   = $this->getUserId();
        if($line_user_id == $userId){
            return $this->error('不能给自己的动态评论');
        }
        $data = [
            'timeline_id'=>$data['timeline_id'],
            'user_id'=>$userId,
            'uniacid'=>$this->_uniacid,
            'content'=> $data['content']
        ];
         $comment->createComment($data);
        return $this->success( [] );
    }
    public function code_pay(){
        $verify = [ 'staff_id' => 'required'];
        $params = lbGetParamVerify( $this->_input, $verify );
        //  是否已经授权过手机号
        $user = new UserPhone();
        $user_id = $this->getUserId();
        $phone  = $user->getUserPhone($user_id,$this->_uniacid);
        //  员工信息
        $userInfoModel = new UserInfo();
        $staff = $userInfoModel->cardList(['fans_id' => $params['staff_id'],'is_staff' => 1]);
        if (!$staff)
        {
            return $this->error('未找到员工信息',403);
        }
        //  公司信息
        $companyModel = new CardCompany();
        if ($staff['company_id'])
        {
            $company = $companyModel->getinfo(['id'=>$staff['company_id']]);
            if (!$company)
            {
                $company = $companyModel->getinfo(['uniacid' => $this->_uniacid]);
            }
        }
        else
        {
            $company = $companyModel->getinfo(['uniacid' => $this->_uniacid]);
        }
        $configModel = new PayqrConfig();
        $config = $configModel->getinfo([ 'uniacid' => $this->_uniacid ]);
        //  没有配置则生成
        if ( !$config ) {
            $configModel->title   = '支付';
            $configModel->uniacid = $this->_uniacid;
            $configModel->save();
            $config = $configModel->getinfo([ 'uniacid' => $this->_uniacid ]);
        }
        $config[ 'is_first' ] = 0;
        //  检查当前用户是否是第一次扫码支付
        $recordModel  = new PayQrRecord();
        $user_id = $this->getUserId();
        $check_record = $recordModel->getinfo([ 'user_id' =>$user_id, 'pay_status' => 1 ]);
        if ( !$check_record ) {
            $config[ 'is_first' ] = 1;
        }
        if (!$config['company_name'] && $company)
        {
            $config['company_name'] = $company['name'];
        }
        if (!$config['company_logo'] && $company)
        {
            $config['company_logo'] = $company['logo'];
        }
        $config['phone'] = '';
        if ($phone)
        {
            $config['phone'] = $phone['phone'];
            $config[ 'is_first' ] = 0;
        }
        return $this->success($config );
    }
    public function payqr(){
        $verify = ['is_first'=>'required','money'=>'required','staff_id'=>0];
        $params = lbGetParamVerify( $this->_input, $verify );
        $card_user = new CardUser();
        $user_id = $this->getUserId();
        $user = $card_user->getUser(['id'=>$user_id]);
        if(!$user){
            return $this->error('用户信息未找到');
        }
        $user_info = new UserInfo();
        $user_staff = $user_info->cardList(['fans_id'=>$params['staff_id']]);
        if(!$user_staff){
            return $this->error('员工信息未找到');
        }
        $money = $params['money'];
        //  是否是第一次购买
        if ( $params['is_first'] ) {
            $configModel = new PayqrConfig();
            $config = $configModel->getinfo([ 'uniacid' => $this->_uniacid ]);
            if ( $config && $config[ 'first_full' ] && $money >= $config[ 'first_full' ] ) {
                $money = $money - $config[ 'first_reduce' ];
                $money = floatval($money);
                $money = sprintf("%.2f", $money);
            }
        }
        //  扫码支付订单号
        $out_trade_no = 'p-'.date('Ymd') . uniqid();
        $record = new PayQrRecord();
        $data = [
            'user_id'=>$user_id,
            'staff_id'=>$params['staff_id'],
            'money'=>$money,
            'out_trade_no'=>$out_trade_no,
            'uniacid'=>$this->_uniacid
        ];
        $record->createRow($data);
        $pay_controller = new IndexWxPay($this->app);
        $jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$user['openid'],$this->_uniacid,"扫码支付",['type' => 'PayQr' , 'out_trade_no' => $out_trade_no,'is_first'=>$params['is_first'],'money'=>$money],floatval($money));
        return $this->success($jsApiParameters);
    }
    //支付回调
    public function qr_notify($arr,$transaction_id){
        $record = new PayQrRecord();
        $order  = $record->getinfo(['out_trade_no' => $arr['out_trade_no']]);
        if ( !$order || $order[ 'pay_status' ] != 0 ) {
            return false;
        }
        $res = $record->upsave(['id'=>$order['id']],['pay_status'=>1,'transaction_id'=>$transaction_id]);
        if($arr['is_first']){
            $message['content'] = '消费金额'.$arr['money'];
        }else{
            $message['content'] = '消费金额'.$order['money'];
        }
        $message['user_id'] = $order['staff_id'];
        $message['target_id'] = $order['staff_id'];
        $message['uniacid'] = $order['uniacid'];
        $message['create_time'] = time();
        $push_data = array(
            'action'  => 'sendMessageWxServiceNotice',
            'event'   => 'longbingSendMessageWxServiceNotice',
            'message' => $message
        );
        publisher(json_encode($push_data ,true));
        return $res;
    }
    /**
     * @Purpose: 名片-插件-扫码支付-支付成功返回推荐商品
     *
     * @Param: int      $staff   员工id

     * @Return: mixed 查询返回值（结果集对象）
     */
    public function pay_goods ()
    {
        $verify = [ 'staff_id' => 'required'];
        $params = lbGetParamVerify( $this->_input, $verify );
        $extensionModel = new CardExtension();
        $we['a.uniacid'] = $this->_uniacid;
        $we['a.user_id'] = $params['staff_id'];
        $we['a.status'] = 1;
        $extension = $extensionModel->getlist($we);
        $goodsModel = new CardGoods();
        if ( !$extension ) {
            $goods = $goodsModel->getlist(['uniacid' => $this->_uniacid, 'status' => 1],4);
        } else {
            $ids = [];
            foreach ( $extension as $k => $v ) {
                array_push($ids, $v[ 'goods_id' ]);
            }
            $ids = implode(',', $ids);
            if ( count($extension) > 1 ) {
                $where = [
                    ['status','=',1],
                    ['id','in',$ids]
                ];
                $goods =$goodsModel->getlist($where);
            } else {
                $goods = $goodsModel->getlist(['id'=>$ids,'status'=>1]);
            }
        }
        foreach ($goods as $key=>$val){
            $goods[$key]['is_collage'] = 0;
            $collage_model  = new IndexShopCollage();
            $count          = $collage_model->getCollage(['goods_id' => $val['id'] ,'uniacid' => $this->_uniacid ,'status' => 1]);
            if(!empty($count)) $goods[$key]['is_collage'] = 1;
        }

        //  轮播图
        $carouselModel = new PayqrCarousel();
        $carousel = $carouselModel->onPageLsit(['uniacid' => $this->_uniacid, 'status' => 1]);
        $data = ['goods' => $goods, 'carousel' => $carousel];
        //  支付记录
        $recordModel = new PayQrRecord();
        $user_id = $this->getUserId();
        $record = $recordModel->getinfo(['user_id' => $user_id,'staff_id'=>$params['staff_id'], 'pay_status' => 1]);
        if($record){
            $record['create_time'] = date('Y-m-d H:i',$record['create_time']);
        }
        //  判断是否显示商品
        $tabBarModel = new LongbingTabbar();
        $info        = $tabBarModel->getTabbar([ 'uniacid' => $this->_uniacid ]);
        $hide = false;
        if(!$info)
        {
            $hide = true;
        }
        $auth_info = false;
        //  检查有没有管理端
        $checkExists = Db::query('show tables like "' . config('database.prefix') . 'longbing_cardauth2_config"');
        //  检查管理端有没有设置版权CardauthConfig
        $cardAuthConfig = new CardauthConfig();
        if ( !empty($checkExists) ) {
            $auth_info = $cardAuthConfig->getinfo( [ 'modular_id' => $this->_uniacid ] );
        }

        if ( $hide === false ) {
            if ($info[ 'menu2_is_hide' ])
            {
                if ( $auth_info && isset($auth_info[ 'shop_switch' ]) && $auth_info[ 'shop_switch' ] == 0 ) {
                    $hide = true;
                }
            }
            else
            {
                $hide = true;
            }
        }
        if ($hide)
        {
            $data['goods'] = [];
        }
        $data['record'] = $record;
        return $this->success($data);
    }
    public function user_send(){
        $verify = [ 'label_id_list' => 'required','content' => 'required'];
        $params = lbGetParamVerify( $this->_input, $verify );
        if(is_array($params['label_id_list'])&&count($params['label_id_list'])>0){
            $params['label_id_list'] = trim( implode( ',', $params['label_id_list'] ), ',' );
        }
        $user_label = new CardUserLabel();
        $where = [
            ['label_id','in',$params['label_id_list']],
            ['uniacid','=',$this->_uniacid]
        ];
        $list = $user_label->getlist($where);
        $value['content'] = $params['content'];
        $value['uniacid'] = $this->_uniacid;
        $user_id = $this->getUserId();
        $value['user_id'] = $user_id;
        $value['create_time'] = time();
        if($list){
            foreach($list as $val){
                $value['target_id'] = $val['user_id'];
                $push_data = array(
                    'action'  => 'sendMessageWxServiceNotice',
                    'event'   => 'longbingSendMessageWxServiceNotice',
                    'message' => $value
                );
                publisher(json_encode($push_data ,true));
            }
        }
        $user_send = new UserSend();
        $params['user_id'] = $user_id;
        $params['type'] = 1;
        $params['uniacid'] = $this->_uniacid;;
//        longbingSendMessageWxServiceNotice($value);
        $rest = $user_send->createRow($params);
        if($rest){
            return $this->success([]);
        }else{
            return $this->error('失败');
        }
    }
    public function send_list(){
        $verify = [ 'type' => 'required'];
        $params = lbGetParamVerify( $this->_param, $verify );
        $user_send = new UserSend();
        $where['uniacid'] = $this->_uniacid;
        $where['user_id'] = $this->getUserId();
        $where['type'] = $params['type'];
        $list = $user_send->getlist($where,$this->page,$this->list_rows);
        return $this->success($list);
    }

    public function category_list(){
        $where[] = ['uniacid','=',$this->_uniacid];
        $where[] = ['modular_id','=',$this->_param['modular_id']];
        $where[] = ['status','=',1];
        $list = (new CardVideoCategory())->lists($where);
        return $this->success($list);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-12-25 09:54
     * @功能说明:明星列表
     */
    public function starList(){

        $input = $this->_param;

        $star_model = new StarList();

        $cate_model = new StarCate();

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        $dis[] = ['a.status','=',1];

        if(!empty($input['modular_id'])){

            $dis[] = ['a.modular_id','=',$input['modular_id']];
        }
        //分类筛选
        if(!empty($input['cate_id'])){
            //查看分类是一级还是二级
            $cate_id   = $cate_model->where(['pid'=>$input['cate_id']])->column('id');

            $cate_id[] = $input['cate_id'];

            $dis[]     = ['a.cate_id','in',$cate_id];
        }
        //标题筛选
        if(!empty($input['title'])){

            $dis[] = ['a.title','like','%'.$input['title'].'%'];
        }

        $type = [];
        //各种条件筛选
        if(!empty($input['choose'])){

           $type = array_column($input['choose'],'type');

           foreach ($input['choose'] as $k=>$v){

               if(!empty($v['list'])){

                   $dis[] = [$v['type'].'.connect_id','in',$v['list']];

                   $dis[] = [$v['type'].'.type','=',$v['type']];

               }

           }

        }

        $data = $star_model->indexList($dis,$type);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-12-24 17:22
     * @功能说明:筛选列表
     */
    public function chooseSelect(){

        $input = $this->_input;

        $choose_model = new StarChoose();

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['status','=',1];

        $dis[] = ['modular_id','=',$input['modular_id']];

        $list = [1,2,3,4];

        foreach ($list as $k=>$value){

            $arr[$k]['type'] = $value;

            $arr[$k]['list'] = $choose_model->where($dis)->where(['type'=>$value])->order('top desc,id desc')->select()->toArray();;

        }

        return $this->success($arr);
    }

    /**
     * @author chenniang
     * @DataTime: 2020-12-23 17:17
     * @功能说明:下拉分类
     */
    public function cateSelect(){

        $cate_model = new StarCate();

        $input = $this->_input;

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['status','=',1];

        $dis[] = ['modular_id','=',$input['modular_id']];

        $data  = $cate_model->where($dis)->field('id,pid,title')->order('top desc,id desc')->select()->toArray();

        $data  = $cate_model->getTree($data,0);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-12-25 13:53
     * @功能说明:二级分类
     */
    public function twoList(){

        $cate_model   = new StarCate();

        $banner_model = new StarBanner();

        $input = $this->_input;

        $data['one'] = $cate_model->where(['id'=>$input['cate_id']])->field('id,title,cover')->find();

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['status','=',1];
        //分类
        $data['cate']   = $cate_model->where($dis)->where(['pid'=>$input['cate_id']])->field('id,title,cover')->order('top desc,id desc')->select()->toArray();
        //banner
        $data['banner'] = $banner_model->where($dis)->where(['cate_id'=>$input['cate_id']])->field('cover')->order('top desc,id desc')->select()->toArray();

        return $this->success($data);

    }

    /**
     * @author chenniang
     * @DataTime: 2020-12-25 14:09
     * @功能说明:明星详情
     */
    public function starInfo(){

        $input = $this->_input;

        $star_model = new StarList();

        $choose_model = new StarChoose();

        $dis = [

            'id' => $input['id']
        ];

        $data = $star_model->startInfo($dis);

        if(empty($data)){

            $this->errorMsg('艺人未找到');
        }
        $data['content']         = str_replace("&amp;nbsp;","",getimgsV2($data['content']));
        //地区
        $data['area']            = $choose_model->chooseData($data['id'],1);
        //艺人分类
        $data['star_cate']       = $choose_model->chooseData($data['id'],2);
        //职业分类
        $data['occupation_cate'] = $choose_model->chooseData($data['id'],3);
        //年龄
        $data['age']             = $choose_model->chooseData($data['id'],4);
        //推荐艺人
        $data['recommend']       = $star_model->recommendList($data['id']);

        return $this->success($data);

    }









}
